package c05.jmm;

import lombok.extern.slf4j.Slf4j;

import static util.Sleeper.sleep;

@Slf4j(topic = "c.Test32")
public class JMMSynchronized {
    // 易变
    static boolean run = true;
    final static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (true) {
                synchronized (lock) {
                    if (!run) {
                        break;
                    }
                }
            }
        });
        t.start();

        sleep(1);
        synchronized (lock) {
            run = false;
        }
    }
}
